/**
 * Created by DukeCrushIt on 2015/8/10.
 */
//module game{
    class DateItemRender extends eui.ItemRenderer{
        public constructor(){
            super();
            this.skinName = "pet.DateItemRenderSkin"
        }

        private onPlay(evt:egret.TouchEvent){
            if(PetMgr.getInstance().curIndatePetId != 0){
                window["__date"](this.data.userId);
                PetMgr.getInstance().othersPet = this.data;
            }

        }

        public dataChanged(){
            super.dataChanged();
            if( this.data instanceof Pet){
                this.lab_name.text = this.data.name;
                this.lab_declration.text = this.data.dateSlogan;
                this.img_female.visible = this.data.sex == 0;
                this.img_male.visible = this.data.sex == 1;
                this.img_pet.source = GameConst.Res_Root+"resource/assets/petpreview/"+this.data.petId+".png";
                this.lab_master_name.text = "主人:"+LimitStringLen(this.data.userName);
            }
        }

        public lab_name:eui.Label;
        public lab_declration:eui.Label;
        public img_play:eui.Image;
        public img_female:eui.Image;
        public img_male:eui.Image;
        public img_pet:eui.Image;
        public img_bg:eui.Image;
        public lab_master_name:eui.Label;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name == "lab_name"){
                this.lab_name = instance;
            }else if( name == "lab_declration"){
                this.lab_declration = instance;
            }else if( name == "img_play"){
                this.img_play = instance;
                this.img_play.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPlay, this);
            }else if( name == "img_female"){
                this.img_female = instance;
            }else if( name == "img_male"){
                this.img_male = instance;
            }else if( name == "img_pet"){
                this.img_pet = instance;
            }else if( name == "img_bg" ){
                this.img_bg = instance;
                this.img_bg.scale9Grid = new egret.Rectangle(12,12,2,2);
                this.img_bg.width = 450;
                this.img_bg.height = 117;
                this.img_bg.cacheAsBitmap = true;
            }else if( name == "lab_master_name"){
                this.lab_master_name = instance;
            }
        }
    }
//}